package learn5exchange

import com.rabbitmq.client.CancelCallback
import com.rabbitmq.client.DeliverCallback
import com.rabbitmq.client.Delivery
import utils.RabbitMqUtils

class ReceiveLogs02 {
    private static EXCHANGE_NAME = "logs"

    static void main(String[] args) {
        def channel = RabbitMqUtils.getChannel()
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout")
        def queueName = channel.queueDeclare().getQueue()
        channel.queueBind(queueName,EXCHANGE_NAME,"")
        println("等待接收消息。。。")
        channel.basicConsume(queueName,true,new DeliverCallback() {
            @Override
            void handle(String consumerTag, Delivery message) throws IOException {
                println("王稳健："+new String(message.getBody(),"UTF-8"))
//                File file = new File("./")
//                file.write(new String(message.getBody(),"UTF-8"))
            }
        },new CancelCallback() {
            @Override
            void handle(String consumerTag) throws IOException {

            }
        })
    }
}
